package LeetCode1;

import java.util.Arrays;

/**
 * 比较字符串最小字母出现频次
 *
 * @author 是阿秋啊
 * @date 2022/03/27 08:44
 **/
public class Num1170 {
//    public static void main(String[] args) {
//        String[] queries = {"bbb", "cc"};
//        String[] words = {"a", "aa", "aaa", "aaaa"};
//        int[] ret = numSmallerByFrequency(queries, words);
//        System.out.println(Arrays.toString(ret));
//    }

    public  int[] numSmallerByFrequency(String[] queries, String[] words) {
        int[] ret = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int fq = findWords(queries[i]);
            int num = 0;
            for (int j = 0; j < words.length; j++) {
                int fw = findWords(words[j]);
                if (fw > fq) {
                    num++;
                }
            }
            ret[i] = num;
        }
        return ret;
    }

    public  int findWords(String s) {
        if (s.length() == 1) {
            return 1;
        }
        int sum = 1;
        char pre = s.charAt(0);
        for (int i = 1; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == pre) {
                sum++;
            }
            if (c - pre < 0) {
                pre = c;
                sum = 1;
            }
        }
        return sum;
    }
}
